/**
 * 
 */
package instant.openvfs.home.event;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/**
 * 
 * @author qiangli
 *
 */
public class InstallShortcutReceiver extends BroadcastReceiver {
	private static final String ACTION_INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";

	public void onReceive(Context context, Intent data) {
		if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
			return;
		}

		installShortcut(context, data);
	}

	private void installShortcut(Context context, Intent data) {
		String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
		Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);

		if (intent.getAction() == null) {
			intent.setAction(Intent.ACTION_VIEW);
		}
		// TODO
		Toast.makeText(context, "Shortcut installed. " + name,
				Toast.LENGTH_SHORT).show();
	}
}
